<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>16.高效的find与findIndex新增方法</title>
</head>

<body>
  <script>
    //值类型查找
    let arr = [1, 2, 3, 4, 5];
    // 会遍历数组，
    let res = arr.find(function (item) {
      return item == 200;
    });
    // 找到了返回值，找不到返回undifined
    console.log(res);

    //引用类型查找,引用类型比较的是内存地址，所以不能用includes
    let lessons = [{ name: 'js' }, { name: 'css' }, { name: 'mysql' }];
    // 会遍历数组，
    let lesson = lessons.find(function (item) {
      return item.name =='mysql';
    });
    // 找到了返回值，找不到返回undifined
    console.log(lesson);
    // 查找元素的下标
    let index = lessons.find(lesson => (lesson.name =='mysql'));
    // 找到了
    console.log(index);  // 1
  </script>
</body>

</html>